<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>景区信息</title>
    <!--引入vue.js库-->
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
    <script src="/js/vue.js"></script>
    <!-- element-ui引入样式 展示数据的-->
    <link rel="stylesheet" href="/css/index.css">
    <!-- element-ui引入组件库 -->
    <script src="/js/index.js"></script>
    <!--引入axios库  从后端获取数据-->
    <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <script src="/js/axios.min.js"></script>
    <!--上传头像-->
    <!--引入style-->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>
<body >
<!--vue必须绑定根标签-->
<div id="app">
    <!--搜索-->
    <el-row>
        <!--一行分为4列-->
        <el-col :span="3">
            <el-input v-model="searchForm.name" size="mini" placeholder="请输入景区名称"></el-input>

        </el-col>
        <el-col :span="3">
            <el-input v-model="searchForm.scenicAddress"  size="mini" placeholder="请输入景区地址"></el-input>
        </el-col>
        <el-col :span="2">
            &nbsp;&nbsp; <el-button type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>&nbsp;
        </el-col>
        <el-col :span="2">

            <el-button type="primary" icon="el-icon-circle-plus-outline" size="mini" @click="handleAdd">添加</el-button>
        </el-col>
        <el-col :span="14">&nbsp;</el-col>
    </el-row>
    <!--table 数据-->
    <el-table
            :data="tableData"
            style="width: 100%">
        <el-table-column
                prop="id"
                label="编号"
                width="180">
        </el-table-column>
        <!--<el-table-column
                prop="code"
                label="景区代码"
                width="180">
        </el-table-column>-->
        <el-table-column
                prop="name"
                label="景区名称"
                 width="180">
        </el-table-column>
<!--        <el-table-column-->
<!--                prop="scover"-->
<!--                label="封面"-->
<!--                width="180">-->
<!--        </el-table-column>-->
        <el-table-column label="封面">
            <template slot-scope="scope">
                <el-image
                        style="width: 50px; height: 50px"
                        :src="scope.row.scover"
                        :fit="fit">
                </el-image>
            </template>
        </el-table-column>
        <!--<el-table-column
                prop="themeCode"
                label="主题代码"
                width="180">
        </el-table-column>-->
       <!-- <el-table-column
                prop="seasonCode"
                label="时节代码"
                width="180">
        </el-table-column>-->
        <el-table-column
                prop="levelCode"
                label="级别"
                width="180">
        </el-table-column>
        <el-table-column
                prop="businessHours"
                label="营业时间"
                width="180">
        </el-table-column>
        <el-table-column
                prop="regionCode"
                label="地域代码"
                width="180">
        </el-table-column>
        <el-table-column
                prop="scenicAddress"
                label="景区地址"
                width="180">
        </el-table-column>
        <el-table-column
                prop="ticketAddress"
                label="购票地址"
                width="180">
        </el-table-column>
        <el-table-column
                prop="mobile"
                label="手机"
                width="180">
        </el-table-column>
        <el-table-column
                prop="phone"
                label="电话"
                width="180">
        </el-table-column>
        <el-table-column
                prop="snav"
                label="导航图"
                width="180">
        </el-table-column>
        <el-table-column
                prop="summary"
                label="景区简介"
                width="180">
        </el-table-column>
        <el-table-column
                prop="sintroduction"
                label="景区介绍"
                width="180">
        </el-table-column>
        <el-table-column
                prop="straffic"
                label="交通指南"
                width="180">
        </el-table-column>
        <el-table-column
                prop="snotice"
                label="须知"
                width="180">
        </el-table-column>
        <el-table-column
                prop="sprotocol"
                label="协议"
                width="180">
        </el-table-column>
        <el-table-column
                prop="isline"
                :formatter="IslineShow"
                label="是否上线"
                width="180">
        </el-table-column>
        <el-table-column
                prop="weight"
                label="推荐度"
                width="180">
        </el-table-column>
        <el-table-column
                prop="istodayshow"
                label="是否web显示每日更新"
                width="180">
        </el-table-column>
        <el-table-column
                prop="oprice"
                label="最佳折扣对应的门市"
                width="180">
        </el-table-column>
        <el-table-column
                prop="dprice"
                label="最优折扣价每日更新"
                width="180">
        </el-table-column>
        <el-table-column
                prop="snums"
                label="已消费门票时实时更新"
                width="180">
        </el-table-column>
        <el-table-column
                prop="onums"
                label="已下订单数实时更新"
                width="180">
        </el-table-column>
        <el-table-column
                prop="smap"
                label="地图"
                width="180">
        </el-table-column>

        <el-table-column label="操作"  fixed="right" width="260px">

            <template slot-scope="scope">
                <el-button
                        size="mini"
                        type="primary"
                        @click="handleEdit(scope.$index, scope.row)">更新</el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>

    <!--分页功能-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[2,5,10,15,20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>

    <!--添加或者更新的form表单-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <!--<el-form-item label="景区代码" :label-width="formLabelWidth">
                <el-input v-model="form.code" autocomplete="off"></el-input>
            </el-form-item>-->
            <el-form-item label="景区名称" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="封面" :label-width="formLabelWidth">
<!--                <el-input v-model="form.scover" autocomplete="off"></el-input>-->
                <el-upload
                        class="avatar-uploader"
                        action="/scenic/uploadFile"
                        name="file2"
                        :show-file-list="false"
                        :on-success="handleFileSuccess"
                        :before-upload="beforeFileUpload">
                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item label="主题代码" :label-width="formLabelWidth">
                <el-select v-model="form.themeCode" placeholder="请选择">
                    <el-option
                            v-for="item in optionsA"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="时节代码" :label-width="formLabelWidth">
                <el-select v-model="form.seasonCode" placeholder="请选择">
                    <el-option
                            v-for="item in optionsB"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="级别代码" :label-width="formLabelWidth">
                <el-input v-model="form.levelCode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="营业时间" :label-width="formLabelWidth">
                <el-input v-model="form.businessHours" autocomplete="off"></el-input>
            </el-form-item>
            <!--<el-form-item label="地域代码" :label-width="formLabelWidth">
                <el-input v-model="form.regionCode" autocomplete="off"></el-input>
            </el-form-item>-->
            <el-form-item label="景区简介" :label-width="formLabelWidth">
                <el-input v-model="form.summary" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区介绍" :label-width="formLabelWidth">
                <el-input v-model="form.sintroduction" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="交通指南" :label-width="formLabelWidth">
                <el-input v-model="form.straffic" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="是否上线" :label-width="formLabelWidth">
                <el-select v-model="form.isline" placeholder="是否上线">
                    <el-option label="是" value="1"></el-option>
                    <el-option label="否" value="0"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="推荐度" :label-width="formLabelWidth">
                <el-input v-model="form.weight" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="是否web显示，每日更新(0,1)" :label-width="formLabelWidth">
                <el-input v-model="form.istodayshow" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="已消费门票数，实时更新" :label-width="formLabelWidth">
                <el-input v-model="form.snums" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="以下订单，实时更新" :label-width="formLabelWidth">
                <el-input v-model="form.onums" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区地址" :label-width="formLabelWidth">
                <el-input v-model="form.scenicAddress" autocomplete="off"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addOrUpdate">确 定</el-button>
        </div>
    </el-dialog>
    <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%"
    >
        <span>确认删除</span>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="DeleteB">确 定</el-button>
  </span>
    </el-dialog>
</div>
<script>
    //js代码
    var vue = new Vue({
        el:"#app",
        data(){ //存放使用的所有属性数据
            return{ //方便编写表单校验
                tableData: [],//表格数据
                currentPage:1,//页码 第几页
                pageSize:5,//每页显示数量
                total:100,//分页总数量
                searchForm:{name:'',scenicAddress:''},//封装查询对象
                dialogFormVisible: false,//是否显示对话框
                title:'部门添加',//默认显示title
                form:{name:'',scenicAddress:''}, //form表单
                formLabelWidth: '120px',//labal宽度
                del:[],
                dialogVisible:false,
                optionsA:[],// 主题下选框集合
                optionsB:[],// 时令下选框集合
                rules:{ //制定下拉选项规则
                    seasoncode:[
                        { required: true, message: '请选择时令', trigger: 'change' }
                    ],
                    themecode:[
                        { required: true, message: '请选择主题', trigger: 'change' }
                    ]
                },
                imageUrl: '',//图片回显Url地址
            }
        },
        created:function(){//页面初始化时，需要执行的业务可以放入该方法
            //调用加载数据方法
            this. loadData();
            //让_this等于当前vue对象
            var _this = this;
            //加载添加的主题下拉数据
            axios.post('/theme/queryAll')  //指定请求的url及参数  get
                .then(function (response) {  //正确返回对象的处理
                    //JSON.stringify   把json转换为json字符串，方便查看
                    console.log(JSON.stringify(response));
                    //判断返回值是否正确
                    if(response.data.code==200){
                        _this.optionsA = response.data.data;
                        console.log(_this.optionsB);
                        //alert(_this.optionsB);
                    }

                })

            //加载添加的时令下拉数据
            axios.post('/season/queryAll')  //指定请求的url及参数  get
                .then(function (response) {  //正确返回对象的处理
                    //JSON.stringify   把json转换为json字符串，方便查看
                    console.log(JSON.stringify(response));
                    //判断返回值是否正确
                    if(response.data.code==200){
                        _this.optionsB = response.data.data;
                        console.log(_this.optionsB);
                        //alert(_this.optionsB);
                    }

                })
        },
        methods:{ //存放所有使用的方法（函数）
            //封装请求数据的方法
            loadData(){
                //定义变量_this=tshi
                var _this = this;
                //axios向后台发请求
                axios.post('/scenic/queryPage', //请求的url
                    {"pageNo":this.currentPage,"pageSize":this.pageSize,
                        "data":{"name":this.searchForm.name,"scenicAddress":this.searchForm.scenicAddress}})//请求参数  json格式
                    .then(function (response) {//回调函数
                        //前端控制台打印  response 是json对象
                        console.log(response);
                        console.log(JSON.stringify(response));
                        //response获取后台数据时，一定加data  response.data相当于从响应的body中获取
                        if(response.data.code==200){
                            //这里面直接写this相当于axios对象 不是vue
                            // this.tableData = response.data.data.list; //错误的
                            _this.tableData = response.data.data.list;
                            _this.total = response.data.data.total;
                        }
                    })
                    .catch(function (error) {//异常处理
                        console.log(error);
                    });
            },
            //每页数量发生变化
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                //调用加载数据方法
                this. loadData();
            },
            //页码（第几页）发生变化
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage=val;
                //调用加载数据方法
                this. loadData();
            },
            //把性别数字转换成字符串
            IslineShow(row, column, cellValue, index) {
                //cellValue status的值
                var returnValue = '';
                if (cellValue == 1) {
                    returnValue = "上线";
                }else {
                    returnValue = "不上线";
                }
                return returnValue;
                // return cellValue==1?"启动":"禁用";
            },
            //搜索方法
            search(){
                this.loadData();
            },
            //跳转更新
            handleEdit(index, row) {
                console.log(index, row);
                //alert(index+","+JSON.stringify(row));
                //row = {"deptName":'xxx',"loc":'xxx',deptNo:xxx}
                //让对话框显示
                this.dialogFormVisible =true;
                //让title值也发生变化
                this.title='部门更新';
                //给表单赋值
                this.form = row;
            },
            //跳转添加
            handleAdd(){
                //让对话框显示
                this.dialogFormVisible =true;
                //让title值也发生变化
                this.title='部门添加';
                //让form清空
                this.form={};
            },
            //真正添加或者更新
            addOrUpdate(){
                //定义请求路径，默认是添加
                var uri = "/scenic/add";
                //判断是否是更新
                if(this.title=='部门更新'){
                    uri="/scenic/update";
                }
                //定义变量_this=tshi
                var _this = this;
                //axios向后台发请求
                axios.post(uri, //请求的url
                    this.form)//请求参数  json格式
                    .then(function (response) {//回调函数
                        //前端控制台打印  response 是json对象
                        console.log(response);
                        console.log(JSON.stringify(response));
                        //response获取后台数据时，一定加data  response.data相当于从响应的body中获取
                        if(response.data.code==200){
                            //提示成功
                            _this.$message({
                                message: '恭喜你，这是一条成功消息',
                                type: 'success'
                            });
                            //关闭弹框
                            _this.dialogFormVisible = false;
                            //重新加载数据
                            _this.loadData();
                        }else {
                            _this.$message.error('错了哦，这是一条错误消息');
                        }
                    })
                    .catch(function (error) {//异常处理
                        console.log(error);
                    });
            },
            //处理删除
            handleDelete(index, row) {
                // console.log(index, row);
                this.dialogVisible=true;
                this.del = row.id;
                console.log(row.id)
                console.log(row.name)
                //  alert(index+","+JSON.stringify(row));
            },




            DeleteB(){
                let _this = this;
                axios.get("/scenic/deleteById?id=" + this.del)
                   // console.log(id)
                    .then(function (response){
                        if(response.data.code==200){
                            //提示成功
                            _this.$message({
                                message: '恭喜你，这是一条成功消息',
                                type: 'success'
                            });
                            //关闭弹框
                            _this.dialogVisible = false;
                            //重新加载数据
                            _this.loadData();
                        }else {
                            _this.$message.error('错了哦，这是一条错误消息');
                        }
                    })
                    .catch(function (error) {//异常处理
                        console.log(error);
                    });
            },
            //处理文件成功后的回调方法
            handleFileSuccess(res, file) {
                //回显上传图片
                this.imageUrl = URL.createObjectURL(file.raw);
                //打印弹出file
                //alert(JSON.stringify(file));
                this.form.scover = file.response.data.filePath;
                this.form.fileName = file.response.data.fileOriginName;
                //  alert(JSON.stringify(this.form));
            },
            //文件上传前的处理方法
            beforeFileUpload(file) {
                //   isJPG = file.type 赋值操作 把图片类型赋值给isJPG   ==  比较值 例如 1=='1' 为true
                //       ===  比较类型  比较值   1==='1'  为false  类型不等
                //const isJPG = file.type === 'image/jpeg';
                //   file.size文件大小，单位是字节
                const isLt5M = file.size / 1024 / 1024 < 5;

                /*if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }*/
                if (!isLt5M) {
                    this.$message.error('上传头像图片大小不能超过 5MB!');
                }
                //返回false不会执行
                return isLt5M;
            },
        }
    })
</script>
</body>
</html>